import {Element} from "../../element";
import {Alias, Children, Column, Editor, Register, Relate, Serialize, Sort} from "../../decorator";
import {Property} from "../../util/element/property";


@Register( "ProductConfig" )
export class ProductCategory extends Element  {

    @Column()
    @Sort()
    @Editor("Number")
    @Alias("序号")
    @Serialize()
    public order: number = 0;

    @Editor("Table")
    @Children(Property)
    @Alias("属性列表")
    @Serialize()
    public properties: Array<Property> = [];


    constructor() {
        super();
    }

    fromJSON(obj) {
        super.fromJSON(obj);
    }

}

@Register( "ProductConfig" )
export class ProductCatalog extends Element  {

    @Column()
    @Sort()
    @Editor("Number")
    @Alias("序号")
    @Serialize()
    public order: number = 0;

    @Editor("Table")
    @Children(ProductCategory)
    @Alias("小类")
    @Serialize()
    public children: Array<ProductCategory> = [];


    constructor() {
        super();
    }

    fromJSON(obj) {
        super.fromJSON(obj);
        this.children.sort((a, b) => a.order - b.order);
    }

}


